#include "btform.h"
#include "ui_btform.h"

#include <QPropertyAnimation>

BTForm::BTForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BTForm)
{
    ui->setupUi(this);

    QPropertyAnimation* animationLine1 = new QPropertyAnimation(ui->line1, "geometry", this);
    animationLine1->setDuration(1500);
    animationLine1->setKeyValueAt(0, QRect(7, 9, 7, 31));
    animationLine1->setKeyValueAt(0.5, QRect(7, 40, 7, 0));
    animationLine1->setKeyValueAt(1, QRect(7, 9, 7, 31));
    animationLine1->setLoopCount(-1);
    animationLine1->start();

    QPropertyAnimation* animationLine2 = new QPropertyAnimation(ui->line2, "geometry", this);
    animationLine2->setDuration(1600);
    animationLine2->setKeyValueAt(0, QRect(21, 9, 7, 31));
    animationLine2->setKeyValueAt(0.5, QRect(21, 40, 7, 0));
    animationLine2->setKeyValueAt(1, QRect(21, 9, 7, 31));
    animationLine2->setLoopCount(-1);
    animationLine2->start();

    QPropertyAnimation* animationLine3 = new QPropertyAnimation(ui->line3, "geometry", this);
    animationLine3->setDuration(1700);
    animationLine3->setKeyValueAt(0, QRect(35, 9, 7, 31));
    animationLine3->setKeyValueAt(0.5, QRect(35, 40, 7, 0));
    animationLine3->setKeyValueAt(1, QRect(35, 9, 7, 31));
    animationLine3->setLoopCount(-1);
    animationLine3->start();

    QPropertyAnimation* animationLine4 = new QPropertyAnimation(ui->line4, "geometry", this);
    animationLine4->setDuration(1700);
    animationLine4->setKeyValueAt(0, QRect(49, 9, 7, 31));
    animationLine4->setKeyValueAt(0.5, QRect(49, 40, 7, 0));
    animationLine4->setKeyValueAt(1, QRect(49, 9, 7, 31));
    animationLine4->setLoopCount(-1);
    animationLine4->start();

    ui->lineBox->hide();
}

BTForm::~BTForm()
{
    delete ui;
}

void BTForm::setIconAndText(const QString &btIcon, const QString &btText, int pageId)
{
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(btText);
    this->pageId = pageId;
}

int BTForm::getPageId() const
{
    return pageId;
}

void BTForm::clearBackground()
{
    ui->btStyle->setStyleSheet("#btStyle:hover { background-color: #D8D8D8; }");
}

void BTForm::showAnimation(bool isShow)
{
    if(isShow)
    {
        ui->lineBox->show();
    }
    else ui->lineBox->hide();
}

void BTForm::mousePressEvent(QMouseEvent *event)
{
    (void) event;

    ui->btStyle->setStyleSheet("#btStyle { background-color: rgb(238, 123, 123); } * { color: #F6F6F6; }");

    emit(btClick(pageId));
}
